// pages/Pet details/Pet details.js
let numq = 0;
var that;
var call = require("../../utils/ajax.js")
var app = getApp();
Page({



    /**
     * 页面的初始数据
     */
    data: {
        admin: "",
        showSB: true,
        //轮播图数据
        ListImg: [],
        motto: 'Hello World',
        URL: "",
        petID: "",
        state: false,
        URL:""

    },
    linkH: function(e) {
        let that = this;
        let address = that.data.motto.city_area + that.data.motto.county_area + that.data.motto.detailed_area;
        let message = {
            phone: that.data.motto.contacts_phone,
            weixin: that.data.motto.contacts_wechat,
            adress: address
        }
        console.log(message)
        that.setData({
            admin: message,
            state: true
        })
    },
    onClose: function(e) {
        console.log(e)
        this.setData({
            state: false
        })
    },
    Tect:function (e){
        let that = this;
        let ID = e.currentTarget.dataset.id;
        let jj = that.data.motto;
        console.log(ID)
        let make1 = "";
        make1 = wx.getStorageSync('openID');
        if(!app.globalData.userState){
            wx.showToast({
                title: '您未登录！',
                icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
                duration: 2000     
              }) 
        }else{
        if(make1!=jj.publisher_id&&make1!=""&&jj.publisher_id!=undefined){
            wx.navigateTo({
                url: '/pages/Apply_adoption/Apply_adoption?pet_id=' + ID
            })
            console.log("dad")
        }else{
            wx.showToast({
                title: '不能领养自己的宠物！',
                icon: 'none', //如果要纯文本，不要icon，将值设为'none'
                duration: 2000
            }) 
        }
    }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
                this.setData({
                        URL:app.globalData.URL
                    })
        // that = this;
        console.log(options.pet_id)
        var admin = this;
        let url = "Pet/selectOnePet?pet_id=" + options.pet_id;
        call.getData1(url, function(res) {
            if(res.msg=="成功"){
                console.log(res)
                admin.setData({
                    motto: res.data.inform,
                    ListImg: res.data.imgurl,
                    petID: options.pet_id
                })
            }else{
                wx.showToast({
                    title: '未知错误，请重试！',
                    icon: 'none', //如果要纯文本，不要icon，将值设为'none'
                    duration: 2000
                })
            }
        }, function() {
            wx.showToast({
                title: '未知错误，请重试！',
                icon: 'none', //如果要纯文本，不要icon，将值设为'none'
                duration: 2000
            })
        })

    },
    adoptPoster:function (){
        var that = this;
        console.log(that.data.petID)
        wx.navigateTo({
            url: '/pages/adoptPoster/adoptPoster?id=' + that.data.petID
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})